package com.study.api;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.study.api.ApiController.DataDTO.Stu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhuzi
 * 2024/12/2 9:18
 */
@Api(tags = "测试sign")
@Slf4j
@RestController
@RequestMapping("/api/sign")
public class SignController {

    @ApiOperation("sign-post")
    @PostMapping("post")
    public Stu formPost(@RequestBody Stu stu) {
        log.info("接收到数据{}", stu);
        Stu stus = new Stu();
        stus.setId(IdUtil.getSnowflakeNextId()).setAge(29).setName("透明");
        return stus;
    }

    @ApiOperation("sign-get")
    @GetMapping("get")
    public String getType(String type, String name, HttpServletRequest request) {
        System.out.println(request.getRemoteAddr());
        log.info("type=[{}] name=[{}]", type, name);
        return type + name;
    }

    @PostMapping("/upload")
    public String upload(@RequestParam MultipartFile file, String type) {
        log.info("类型[{}]", type);
        log.info("文件名[{}]", file.getOriginalFilename());
        return RandomUtil.randomString(5);
    }
}
